function convert(input) { alert('Error. Contact us if this keeps happening.'); document.getElementById('modal-contact').classList.add('show'); } window.ctMaxUploadFiles = 1; function _ctPixOutType(name) { var ext = ((name || '').toLowerCase().split('.').pop()); if (ext === 'jpg' || ext === 'jpeg') return { mime: 'image/jpeg', ext: '.jpg' }; if (ext === 'webp') return { mime: 'image/webp', ext: '.webp' }; return { mime: 'image/png', ext: '.png' }; } function processFile(blob, fileName) { var raw = parseInt(($('input[name="0"]').val() || '12'), 10); if (!isFinite(raw)) raw = 12; var block = Math.max(2, Math.min(128, raw)); var img = new Image(); img.onload = function() { var w = img.naturalWidth || img.width; var h = img.naturalHeight || img.height; if (!w || !h) { alert('Could not read this image.'); return; } var smallW = Math.max(1, Math.round(w / block)); var smallH = Math.max(1, Math.round(h / block)); var small = document.createElement('canvas'); small.width = smallW; small.height = smallH; var sctx = small.getContext('2d'); sctx.imageSmoothingEnabled = true; sctx.drawImage(img, 0, 0, smallW, smallH); var out = document.createElement('canvas'); out.width = w; out.height = h; var octx = out.getContext('2d'); octx.imageSmoothingEnabled = false; octx.mozImageSmoothingEnabled = false; octx.webkitImageSmoothingEnabled = false; octx.msImageSmoothingEnabled = false; octx.drawImage(small, 0, 0, w, h); var info = _ctPixOutType(fileName); out.toBlob(function(outBlob) { if (!outBlob) { alert('Could not encode the pixelated image.'); return; } var base = (fileName || 'image').replace(/\.[^.]+$/, ''); add_file_output(URL.createObjectURL(outBlob), base + '-pixelated' + info.ext); }, info.mime, info.mime === 'image/jpeg' ? 0.92 : undefined); }; img.onerror = function() { alert('Could not decode this image file.'); }; img.src = URL.createObjectURL(blob); } var _loadedScripts = {}; function loadScriptPromise(url) { if (_loadedScripts[url]) return _loadedScripts[url]; _loadedScripts[url] = new Promise(function (resolve, reject) { var s = document.createElement('script'); s.src = url; s.onload = resolve; s.onerror = reject; document.head.appendChild(s); }); return _loadedScripts[url]; } function replaceAll(find, replace, str) { return str.replace(new RegExp(find, 'g'), replace); } function beautify(str) { var result = ''; var length = str.length; var i = 0; var braceCountLeft = 0; var braceCountRight = 0; var withinQuotes = false; while (i < length) { var c = str[i]; if (c == '"' && (i == 0 || c[i - 1] != '\\')) { // non-escaped quotes withinQuotes = !withinQuotes; } if (!withinQuotes && (c == '}' || c == '{' || c == ',')) { console.log('Start####' + result); // look back and remove carriage returns and whitespace that are already there var resultIndex = result.length - 1; while (resultIndex >= 0 && (result[resultIndex] == ' ' || result[resultIndex] == '\r' || result[resultIndex] == '\n' || result[resultIndex] == '\t')) { resultIndex = resultIndex - 1; result = result.substr(0, resultIndex + 1); console.log('char ' + result[resultIndex] + '-----' + result + 'zzz ' + result.length + ' ' + resultIndex); } if (c == '{') { braceCountLeft++; result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } else if (c == '}') { braceCountRight++; // precede with carriage return result += '\r' + GetTabs(braceCountLeft - braceCountRight) + c; } else if (c == ',') { result += c + '\r' + GetTabs(braceCountLeft - braceCountRight); } var nextChar = ''; // advance through whitespace and remove carriage returns that are already there while (i < length && (str[i + 1] == ' ' || str[i + 1] == '\r' || str[i + 1] == '\n' || str[i + 1] == '\t')) { i++; } } else { result += str[i]; } i++; } return result; } function GetTabs(count) { var result = ''; for (var i = 0; i < count; i++) { result += ' '; } return result; }